import logging
import paste

from eshop.lib.base import *

log = logging.getLogger(__name__)

class ImageController(BaseController):
    
    def index(self, id):
        try:
            path = g.image_storage.get_thumbnail_path(int(request.params.get('image_id')), id, \
                        int(request.params.get('width')), int(request.params.get('height')), \
                        request.params.get('format'))
            fapp = paste.fileapp.FileApp(path)
            return fapp(request.environ, self.start_response)
        except e:
            log(e)
            return 'Broken image'
            
    def view(self, id):
        return self.index(id)
